<template>
  <div>
      <ul class="list">
          <li @click='click'
              @touchstart='tStart'
              @touchmove='tMove'
              @touchend='tEnd'
              :ref='item'
              v-for="(item,key) of letters" :key='key' class="item">{{item}}</li>
      </ul>
  </div>
</template>

<script>
export default {
  name: 'alp',
  props: ['ar'],
  data () {
    return {
      sY: 0
    }
  },
  mounted () {
  },
  computed: {
    letters () {
      let arr = []
      for (let i in this.ar.cities) {
        arr.push(i)
      }
      return arr
    }
  },
  updated () {
  },
  methods: {
    click (e) {
      this.$emit('letterClick', e.target.innerText)
    },
    tStart () {
      this.touchStatu = true
    },
    tMove (e) {
      let sY = this.$refs['A'][0].offsetTop
      if (this.touchStatu) {
        let nY = e.touches[0].clientY - 72
        let index = Math.floor((nY - sY) / 20)
        console.log(sY, nY, index)
        if (index >= 0 && index < this.letters.length) {
          this.$emit('letterClick', this.letters[index])
        }
      }
    },
    tEnd () {
      this.touchStatu = false
    }
  }
}
</script>

<style lang='stylus' scoped>
@import '~styles/varibles.styl'
 .list
  height :100%
  position: absolute
  right :0
  top:1.58rem
  display :flex
  flex-direction column
  justify-content :center
  .item
   line-height :.4rem
   text-align :center
   color :$bgColor
</style>
